package com.snr.userhistoryprocessor.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.snr.userhistoryprocessor.dao.ReadingLogDao;
import com.snr.userhistoryprocessor.pojo.ReadingLog;
import com.snr.userhistoryprocessor.pojo.User;

public class ReadingLogDaoImpl extends HibernateDaoSupport implements ReadingLogDao {

	public void addReadingLog(ReadingLog readingLog) {
		// TODO Auto-generated method stub
		List list = getHibernateTemplate().find("from ReadingLog where userId=" + readingLog.getUserId() + " and url='"+ readingLog.getUrl() +"'");
		if (list.size() == 0) {
			getHibernateTemplate().save(readingLog);
		}
	}

	@Override
	public List<ReadingLog> getReadingLogs(User user) {
		// TODO Auto-generated method stub
		List list = getHibernateTemplate().find("from ReadingLog where userId=" + user.getId());
		return list;
	}

}
